<?php
	include('secure_db.php');
	session_start();
	
	if (isset($_POST['Password']) AND isset($_POST['Login'])){

		include("connection_mysqli.php");
		
		$req=$connexion->prepare('SELECT address,BP,city,slogan,ophour,GPSlat,GPSlon,dateinscription,password FROM Store WHERE name=?');
		$req->bind_param("s",$val1);
		$val1= Secure::db($_POST['Login']);
		$result=$req->execute();
		$req->bind_result($col2,$col3,$col4,$col5,$col6,$col7,$col8,$col9,$col10);
		
		/*verif result*/
		if (!$req) {
			die('Could not query' . mysql_error());
			echo("fail !req");
		}
		
		/*fetch data*/
		$ok=0;
		while ($donnees = $req->fetch()){
			if(crypt(Secure::db($_POST['Password']),$col10)==$col10){
			$ok=1;
			$_SESSION['name'] = $val1;
			$_SESSION['address'] =$col2;
			$_SESSION['BP'] =$col3;
			$_SESSION['city'] =$col4;
			$_SESSION['slogan'] =$col5;
			
			$_SESSION['ophour'] =$col6;
			$chunks = explode('/',$col6);
			$_SESSION['Lundi'] =$chunks[0];
			$_SESSION['Mardi'] =$chunks[1];
			$_SESSION['Mercredi'] =$chunks[2];
			$_SESSION['Jeudi'] =$chunks[3];
			$_SESSION['Vendredi'] =$chunks[4];
			$_SESSION['Samedi'] =$chunks[5];
			$_SESSION['Dimanche'] =$chunks[6];
			
			$_SESSION['GPSlat'] =$col7;
			$_SESSION['GPSlon'] =$col8;
			$_SESSION['storeonline']=true;
			$_SESSION['clientonline']=false;
			}
				
		}
			
		$req->close();
		$connexion->close();
		if($ok=1){
			header('Location: store-mystore.php');
		}else{
			header('Location: accueil.php');
		}
}
else{
	header('Location: accueil.php');
}

?>
